<template>
  <div class="container">
    <div :class="headerStatus == true? 'headeranimate':'header'">
      <img src="./../assets/images/login/loginbg.png" alt />
    </div>
    <div :class="formStatus == true? 'formanimatin':'form'">
      <div class="title">登录绑定</div>
      <div class="title2">欢迎来到营销平台</div>
      <div class="input">
        <input type="text" placeholder="请输入姓名" @focus="changeStatus()" v-model="name" />
      </div>
      <div class="input">
        <input type="text" placeholder="请输入工号" @focus="changeStatus()" v-model="number" />
      </div>

      <div class="btn">
        <van-button type="default" class="submit" color="#DBB47F" @click="login()">登录</van-button>
      </div>
    </div>
  </div>
</template>
<script>
import { Toast } from "vant";
import Api from "./../api/api";
export default {
  components: {},
  data() {
    return {
      formStatus: false,
      headerStatus: false,
      name: "",
      number: ""
    };
  },
  methods: {
    changeStatus() {
      this.formStatus = true;
      this.headerStatus = true;
    },
    login() {
      if (this.name == "") {
        Toast("请输入姓名");
        return false;
      }

      if (this.number == "") {
        Toast("请输入工号");
        return false;
      }

      this.$axios
        .post(Api.HTTP.bind, {
          wechatOpenId: localStorage.getItem("openId"),
          code: this.number,
          name: this.name
        })
        .then(res => {
          console.log(res);
          if (res.data.success) {
            this.findUserExist();
          } else {
            Toast(res.data.msg);
          }
        })
        .catch(function(error) {
          Toast("网络错误");
        });
    },
    findUserExist() {
      this.$axios
        .get(
          `${Api.HTTP.findUserExist}?wechatOpenId=${localStorage.getItem(
            "openId"
          )}`
        )
        .then(res => {
          Toast("绑定成功");
          localStorage.setItem("employeeCode", res.data.data.code);
          setTimeout(() => {
            this.$router.push({ path: "/ManagerHomePage" });
          }, 1500);
        })
        .catch(function(error) {
          Toast("网络错误");
        });
    }
  },
  mounted() {
    if (
      localStorage.getItem("openId") == null &&
      localStorage.getItem("openId") != "undefined"
    ) {
      Toast("登录过期");
      this.$router.push({ path: "/wechatLogin" });
    }
    if (
      localStorage.getItem("employeeCode") != null &&
      localStorage.getItem("employeeCode") != "undefined"
    ) {
      this.$router.push({ path: "/ManagerHomePage" });

      // window.location.href = `https://bjxsq.jsruiyin.com/ygtActivity/pt/index.html#/ManagerIndex?code=${localStorage.getItem('employeeCode')}`
    }

    this.pubilcM.setTitle("登录");
  }
};
</script>
<style scoped>
.container {
  width: 100%;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  overflow: hidden;
  overflow-y: auto;
}
.title {
  font-size: 0.5rem;
  font-weight: bold;
  margin-bottom: 0.2rem;
}
.title2 {
  color: #999999;
  font-size: 0.27rem;
  margin-bottom: 1rem;
}
.btn {
  width: 100%;
  margin-top: 1rem;
}
.submit {
  width: 100%;
}
.input {
  width: 100%;
  margin-bottom: 0.4rem;
}
input {
  padding-bottom: 0.2rem;
  padding-top: 0.15rem;
  width: 100%;
  border: 0px;
  outline: none;
  border-bottom: 1px solid #dbb47f;
}
input ::placeholder {
  color: #999999;
}
.header {
  width: 100%;
  height: 2.3rem;
}
.header > img {
  width: 100%;
  height: 100%;
}
.form {
  padding: 0.6rem 0.4rem 7rem 0.3rem;
  box-sizing: border-box;
  position: absolute;
  top: 1.5rem;
  height: 5rem;
  width: 100%;
  border-radius: 0.3rem;
  background: #fff;
  z-index: 999;
}

.headeranimate {
  width: 100%;
  height: 2.3rem;
  animation: up 1s infinite;
  -webkit-animation: up 1s infinite;
  animation-iteration-count: 1;
}

.formanimatin {
  padding: 0.6rem 0.4rem 7rem 0.3rem;
  box-sizing: border-box;
  position: absolute;
  top: 0;
  height: 5rem;
  width: 100%;

  background: #fff;
  animation: up 1s infinite;
  -webkit-animation: up 1s infinite;
  animation-iteration-count: 1;
}

@keyframes up {
  0% {
    top: 1.5rem;
  }

  100% {
    top: 0rem;
  }
}

@keyframes dowmForm {
  0% {
    top: 1.5rem;
  }

  100% {
    top: 0rem;
  }
}

@keyframes headerup {
  0% {
    height: 2.3rem;
  }

  50% {
    height: 1.2rem;
  }

  100% {
    height: 0rem;
  }
}

@keyframes headerdowm {
  0% {
    height: 0rem;
  }

  50% {
    height: 1.2rem;
  }

  100% {
    height: 2.3rem;
  }
}
</style>